﻿namespace HuwmanCode.Transactions

open System
open System.Transactions

type public CommitAction(action) as this=
    do
        Transaction.Current.EnlistVolatile(this, EnlistmentOptions.None) |> ignore  

    static member Enlist(action) = new CommitAction(action) |> ignore

    interface IEnlistmentNotification with
        member this.Commit(enlistment) =
            try
                action()
            with _ -> ()
            enlistment.Done()

        member this.InDoubt(enlistment) =
            enlistment.Done()

        member this.Prepare(prepEnlistment) =
            prepEnlistment.Prepared()

        member this.Rollback(enlistment) =
            enlistment.Done()